<div class="ajaxLoading">
<img src='<?php echo $engineReturn['admin_template']?>css/images/loading.gif' width="50" align="middle" />
</div>
<div class='ajaxGrid'>
<?php
//echo "<pre>";
//print_r($engineReturn['record']);
	echo "<a href='#' class='aNav' id='insert_new_div'>Insert New</a>";
	if(isset($engineReturn['record']['msg']) && is_array($engineReturn['record']['msg']))
		foreach($engineReturn['record']['msg'] as $msg)
		{
			echo "<div class='inlineMessage'>$msg</div>";
		}
	$total		= $engineReturn['record']['recTotal'];
	$startOri	= $engineReturn['record']['recStart'];
	$count		= $engineReturn['record']['recPage'];
	$start		= $startOri/$count;
	$start++;
	$pageCount 	= ceil($total/$count);
	$step		= 4;
	$nav[0]		= 1;
	$res	= $engineReturn['record']['records'];
	for($i = 2; $i <= $pageCount; $i++)
	{
		if(($i==$start)
		|| ($i<$step)
		|| (($i>$start-$step) & ($i<$start))
		|| (($i<$start+$step) & ($i>$start))
		|| ($i>$pageCount-$step)
		)
		{
			$nav[count($nav)] = $i;
		}
	}
	echo "<table class='table'>";
	echo "<tr><td>";
	foreach($nav as $i=>$n)
	{
		if(($i>0) && ($nav[$i]-$nav[$i-1]>1))
			echo "..";
		echo "<a href='#' class='aNav navigasi_grid ".(($n==$start)?"aNavdisabled":"")."'>".$n."</a>";
	}
	echo " Rows";
	echo "<select id='rowGrid'>";
		echo "<option value=''>--</option>";
		echo "<option value='5' ".(($count==5)?"selected='selected'":"").">5</option>";
		echo "<option value='10' ".(($count==10)?"selected='selected'":"").">10</option>";
		echo "<option value='20' ".(($count==20)?"selected='selected'":"").">20</option>";
		echo "<option value='50' ".(($count==50)?"selected='selected'":"").">50</option>";
		echo "<option value='100' ".(($count==100)?"selected='selected'":"").">100</option>";
	echo "</select>";
	echo "</td></tr>";
	echo "</table>";
	echo "<table class='table'>";
	echo "<tr>";
		echo "<th colspan='2'>";
		echo "</th>";
		foreach($engineReturn['record']['fields'] as $i=>$v)
		{
			echo "<th>";
				echo $v['text'];
			echo "</th>";
		}
	echo "</tr>";
	for($i = 0; $i<count($res); $i++)
	{
		$id	= $res[$i]['idRec'];
		echo "<tr>";
				echo "<td>";
				echo "<a href='#' idrec='$id' title='Press Here to Delete Data' class='delete_data_on_grid'>";
					echo "<img src='".$engineReturn['admin_template']."css/images/del.png' />";
				echo "</a>";
				echo "</td>";
			echo "<td>".($startOri+$i+1)."</td>";
			foreach($engineReturn['record']['fields'] as $v)
			{
					$fieldName	= $v['name'];
					echo "<td class='tdGrid'>";
					echo "<div class='columnGrid'>";
						echo "<a idvalue='$id' fieldname='$fieldName' href='#' class='editIcon'>";
						echo "<img src='".$engineReturn['admin_template']."css/images/edit.png' />";
						echo "</a>";
					echo "</div>";
					echo "<div>";
					switch($v['input'])
					{
						case "hidden":
						case "text":
						case "text_primary":
						case "password":
						case "text_area":
						case "text_area_plus_editor":
							echo $res[$i][$fieldName];
						break;
						case "checkbox":
							if(is_array($res[$i][$fieldName]))
							{
								foreach($res[$i][$fieldName] as $v)
								{
									echo $v.", ";
								}
							}
						break;
						case "image":
							if($res[$i][$fieldName]!="")
								echo "<div class='defContainerImage'>"
									."<img src='".$res[$i][$fieldName]."'>"
									."</div>";
						break;
						case "file":
							if($res[$i][$fieldName]!="")
								echo "<a href='".$res[$i][$fieldName]."' target='_SELF'>"
									."DOWNLOAD</a>";
						break;
						case "radio":
						case "select":
							if(isset($res[$i][$fieldName][1]))
								echo $res[$i][$fieldName][1];
							else
								echo $res[$i][$fieldName][0];
						break;
						case "simple_table":
							if(isset($res[$i][$fieldName]['dataRec']))
								echo $res[$i][$fieldName]['dataRec'];
							else
								echo "-";
						break;
						case "medium_table":
						case "advance_table":
							if(isset($res[$i][$fieldName][1]))
								$rs = count($res[$i][$fieldName][1]);
								echo "<table>";
								echo "<tr>";
								if(isset($res[$i][$fieldName][1]) && (is_array($res[$i][$fieldName][1])))
								{
										foreach($res[$i][$fieldName][1] as $t)
										{
											echo "<td>".$t."</td>";
										}
								}
								echo "</tr>";
								echo "<tr>";
								if(isset($res[$i][$fieldName][0][0]) && (is_array($res[$i][$fieldName][0][0])))
								{
										foreach($res[$i][$fieldName][0][0] as $t)
										{
											echo "<td>".$t."</td>";
										}
								}
								else
								{
									echo "<td colspan='$rs'>";
								}
								echo "</tr>";
								echo "</table>";
						break;
					echo "</div>";
					echo "</td>";
				}
			}
		echo "</tr>";
	}
?>
</table>
</div>
<script type="text/javascript">
	$('.ajaxGrid').delay(100).slideDown('slow', function(){
			$('.ajaxLoading').slideUp('slow');
	});
	$('.navigasi_grid').navigateViewData({
		url 			: '<?php echo $baseUrlSave;?><?php echo $otority;?>/engine/<?php echo $engineReturn['modulename'] ?>/ajax/sub/data/nav/<?php echo $engineReturn['record']['idMaster'];?>/',
		div_loading 	: 'ajaxLoading',
		div_grid		: 'ajaxGrid',
		div_container 	: 'containerGrid',
		count			: '<?php echo $count?>',
		start			: ''
		});
	$('#rowGrid').navigateViewData({
		url 			: '<?php echo $baseUrlSave;?><?php echo $otority;?>/engine/<?php echo $engineReturn['modulename'] ?>/ajax/sub/data/nav/<?php echo $engineReturn['record']['idMaster'];?>/',
		div_loading 	: 'ajaxLoading',
		div_grid		: 'ajaxGrid',
		div_container 	: 'containerGrid',
		count			: '',
		start			: '<?php echo $start?>',
		changeRow		: true
		});
	$('.delete_data_on_grid').subInputDeleteData({
		url 			: '<?php echo $baseUrlSave;?><?php echo $otority;?>/engine/<?php echo $engineReturn['modulename'] ?>/ajax/sub/data/del/<?php echo $engineReturn['record']['idMaster'];?>/',
		div_loading 	: 'ajaxLoading',
		div_grid		: 'ajaxGrid',
		div_container 	: 'containerGrid',
		count			: '<?php echo $count?>',
		start			: '<?php echo $start?>'
		});
	$('#insert_new_div').navigateToInsertData({
		url 			: '<?php echo $baseUrlSave;?><?php echo $otority;?>/engine/<?php echo $engineReturn['modulename'] ?>/ajax/sub/data/ins/<?php echo $engineReturn['record']['idMaster'];?>/',
		div_loading 	: 'ajaxLoading',
		div_grid		: 'ajaxGrid',
		div_container	: 'containerGrid',
		});
	$('.tdGrid').hover(function(){
			$(this).find('.columnGrid').show('slow', function(){
				$(this).find('.editIcon').slideDown('medium');
				});
		}, function(){
			$(this).find('.editIcon').slideUp('medium', function(){
				$(this).parent().hide('slow');
			});
		});
	$('.editIcon').navigateToEditData({
		url 			: '<?php echo $baseUrlSave;?><?php echo $otority;?>/engine/<?php echo $engineReturn['modulename'] ?>/ajax/sub/data/edt/<?php echo $engineReturn['record']['idMaster'];?>/',
		});
</script>